<template>
	<view>
		<navbar title="" :autoBack="true">
			<view class="" slot='centerbtn'>
				<u-tabs :list="list4" lineWidth="32rpx" lineHeight='6rpx' lineColor="#3A4E6D" :activeStyle="{
				            color: '#1E1E1E',
				            fontWeight: 'bold',
							transform: 'scale(1)'
				        }" :inactiveStyle="{
				            color: '#6F7271',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 42rpx; padding-right: 42rpx; height: 60rpx;font-size:34rpx;" @click="clicktab">
				</u-tabs>
			</view>
		</navbar>
		<view class="con">
			<u-search height="90rpx" @change="getlist" bgColor="#FFFFFF" searchIconSize='42rpx' margin='0 0 25rpx' :showAction='false' placeholder="搜索商品或服务" placeholderColor='#8D8D8D' v-model="keyword"></u-search>
			<scroll-view scroll-y="true" class="scbox">
				<view class="con__list" v-if="loading">
					<view class="con__list__item" v-for="(item,index) in goodslist" :key="index" @click="navto('/pages/goods/details?id='+item.id)">
						<image :src="URL(item.image)" class="con__list__item__pic" mode="aspectFill"></image>
						<view class="con__list__item__info">
							<view class="con__list__item__info__name u-line-1">
								{{item.name}}
							</view>
							<view class="u-flex u-flex-y-center">
								<view class="con__list__item__price">
									<text style="font-size: 24rpx;">￥</text>{{item.price}}
								</view>
								<view class="con__list__item__oldprice">
									￥{{item.oldprice}}
								</view>
							</view>
							<view class="u-flex u-flex-y-center">
								<view class="con__list__item__tip">
									月销{{item.monthnum}}件
								</view>
							</view>
						</view>
					</view>
				</view>
				<u-loading-icon :show='!loading'></u-loading-icon>
			</scroll-view>
			
		</view>
	</view>
</template>

<script>
	import goods from '@/api/_goods.js'
	export default {
		data() {
			return {
				list4:[
					{name:'商品',type:1},
					{name:'服务',type:2},
					{name:'药膳',type:3},
				],
				keyword:'',
				goodslist:[],
				loading:false,
				type:1
			};
		},
		methods:{
			getlist(){
				this.loading=false
				goods.getGoods({type:this.type,keyword:this.keyword,status:2}).then(res=>{
					this.loading=true
					if(res.data.code==1){
						this.goodslist=res.data.data
					}
				})
			},
			clicktab(e){
				this.type=e.type
				this.getlist()
			}
		},
		onLoad(){
			this.getlist()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f3f7;
	}
	.con{
		padding: 20rpx 30rpx 0;
		.scbox{
			height: calc(100vh - var(--status-bar-height) - 44px - 80rpx - 90rpx - 25rpx);
			
		}
		&__list{
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;
			&__item{
				width: 335rpx;
				border-radius: 20rpx;
				overflow: hidden;
				background-color: #fff;
				margin-bottom: 24rpx;
				&__pic{
					width: 335rpx;
					height: 335rpx;
					background: #ccc;
				}
				&__info{
					padding: 20rpx 17rpx;
					margin-top: -4px;
					&__name{
						width: 300rpx;
						font-family: PingFang SC;
						font-weight: bold;
						font-size: 28rpx;
						color: #181818;
						line-height: 28rpx;
						margin-bottom: 24rpx;
					}
				}
				
				&__price{
					font-family: DIN Next LT Pro;
					font-weight: 500;
					font-size: 36rpx;
					color: #FD2A00;
					line-height: 40rpx;
					margin-right: 9rpx;
				}
				&__oldprice{
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 22rpx;
					color: #919191;
					line-height: 22rpx;
					text-decoration-line: line-through;
					margin-bottom: 10rpx;
				}
				&__tip{
					padding: 6rpx;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 19rpx;
					color: #6A6A6A;
					line-height: 19rpx;
					border: 2rpx solid #D9D9D9;
					margin-top: 10rpx;
				}
			}
		}
	}
</style>